package com.baizhi.util;

import com.baizhi.service.CmfzUserService;
import com.google.gson.Gson;
import io.goeasy.GoEasy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: renpu
 * @Date: 2019/3/5 19:30
 * @Description:
 */

//将生成得GoEasyUtil交给spring工厂管理
@Component
public class GoEasyUtil {

    //自动装配
    @Autowired
    private CmfzUserService userService;


    //通过goeasy进行发布；
    public void publish(){

        List<Integer> list=new ArrayList<>();
        int mCont=userService.selectManCount();
        int gCont=userService.selectGirlCount();

        list.add(mCont);
        list.add(gCont);
        Gson gson=new Gson();
        String content=gson.toJson(list);

        //创建GoEasy对象传入已注册获取的regionHost和appkey
        GoEasy goEasy=new GoEasy("https://rest-hangzhou.goeasy.io","BC-bc0efc3ab30840fcbdc87e9222df0107");
        goEasy.publish("my_channel",content);

    }






}
